﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FirmaTransportowa
{



    public partial class AdminPanelUserView : Form
    {

        SqlConnection dbConnection2;

        public AdminPanelUserView()
        {
            SqlConnector connection = new SqlConnector();
            dbConnection2 = connection.getInstance();
            InitializeComponent();
        }

        private void nowaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminAddNewUser adminAddNewUser = new AdminAddNewUser(this);
            adminAddNewUser.Show();
        }

        private void dodajToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AdminAddNewWorker adminAddNewWorker = new AdminAddNewWorker();
            adminAddNewWorker.Show();
        }

        private void adminPanelCarViewMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
            AdminPanelCarView adminPanelCarView = new AdminPanelCarView();
            adminPanelCarView.Show();
        }

        private void usuńToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void adminPanelWorkerViewMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
            AdminPanelWorkerView adminPanelWorkerView = new AdminPanelWorkerView();
            adminPanelWorkerView.Show();
        }

        private void pracownikToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void AdminPanel_Load(object sender, EventArgs e)
        {

            // TODO: This line of code loads data into the 'transportDataSet.Users' table. You can move, or remove it, as needed.
            //this.usersTableAdapter.Fill(this.transportDataSet.Users);
            //this.workersTableAdapter.Fill(this.transportDataSet5.Workers);
       

        }

        private void addUserButton_Click(object sender, EventArgs e)
        {
            AdminAddNewUser adminAddNewUser = new AdminAddNewUser();
            adminAddNewUser.Show();
            //this.usersTableAdapter.Fill(this.transportDataSet.Users);
            usersDataGridView.Update();
            usersDataGridView.Refresh();
           
        }

        private void workersDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                //this.workersTableAdapter.FillBy(this.transportDataSet6.Workers);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void usersDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //this.usersTableAdapter.Fill(this.transportDataSet.Users);
        }

        private void deleteUserButton_Click(object sender, EventArgs e)
        {
            dbConnection2.Open();
            SqlCommand cmd = new SqlCommand("DELETE FROM Users WHERE user_ID=@user_ID");
            cmd.Connection = dbConnection2;
            cmd.Parameters.AddWithValue("@user_ID", usersDataGridView.Rows[usersDataGridView.CurrentRow.Index].Cells[0].Value.ToString());
            cmd.ExecuteNonQuery();
            dbConnection2.Close();
            //this.usersTableAdapter.Fill(this.transportDataSet.Users);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            refreshUserGridViewContent();
        }

        private void changeToWorkerViewButton_Click(object sender, EventArgs e)
        {
            this.Close();
            AdminPanelWorkerView adminPanelWorkerView = new AdminPanelWorkerView();
            adminPanelWorkerView.Show();
        }

        public void refreshUserGridViewContent()
        {
            //this.usersTableAdapter.Fill(this.transportDataSet.Users);
        }

        private void refreshButton_Click(object sender, EventArgs e)
        {
            //this.usersTableAdapter.Fill(this.transportDataSet.Users);
        }

        private void AdminPanelUserView_FormClosed(object sender, FormClosedEventArgs e)
        {
            
        }
    }
}
